package com.homelock.constants;

/**
 * 振兴开门记录类型枚举
 *
 * @author chenmf@163.com
 * @date 2020年07月15日01:57:21
 */
public enum LockCmdEnum {
    /**
     * 门锁指令上报枚举
     */
    EMPTY("", -1, -1, "空"),
    ADD_USER("4_7", 0x07, 4, "添加用户"),
    DEL_USER("4_8", 0x08, 4, "删除用户"),
    OPEN_RECORD("0", -1, 0, "开门记录"),
    ALARM_RECORD("2", -1, 2, "报警记录");
    /**
     * processor分类code 格式 optCode + (code 可选)
     */
    String value;
    /**
     * 分类code(数据描述)
     */
    byte code;
    /**
     * 指令code(数据类型)
     */
    byte optCode;
    /**
     * 指令描述
     */
    String name;

    LockCmdEnum(String value, int code, int optCode, String name) {
        this.name = name;
        this.value = value;
        this.code = (byte) code;
        this.optCode = (byte) optCode;
    }

    public static LockCmdEnum codeOf(byte code) {
        for (LockCmdEnum item : values()) {
            if (item.getCode() == code) {
                return item;
            }
        }
        return EMPTY;
    }

    public static LockCmdEnum optCodeOf(byte optCode) {
        for (LockCmdEnum item : values()) {
            if (item.getOptCode() == optCode) {
                return item;
            }
        }
        return EMPTY;
    }

    public String getValue() {
        return value;
    }

    public String getName() {
        return name;
    }

    public byte getCode() {
        return code;
    }

    public byte getOptCode() {
        return optCode;
    }
}
